/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"93905F86-F792-41F0-A274-284410F3A09C",variableType:4}
 */
var fDeudaPaga = 0;


/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6F1EE3A3-2D3F-4F6A-B8DC-7CF5F454AEFF"}
 */
function buscar(event) {
	var $campo_tb
	if (fDeudaPaga == 0)
	{
		$campo_tb = 'tb.diario_compras'
	}
	else
	{
		$campo_tb = 'tb.diario_pagos'
	}
	var $query = 'select cc.centro_id, SUM(importe) as "total" FROM ctacte_pr "cc" '+
					' JOIN tab_mov_pr "tb" ON cc.cod_mov = tb.ctacte_mov_pr_id '+
					' WHERE ' + $campo_tb + ' = 1 AND cc.fecha_mov BETWEEN ? and ? AND centro_id is not null '+
					' group by cc.centro_id order by cc.centro_id '
	/** @type {Array<Object>}*/
	var args = [globals.gFechaDesde, globals.gFechaHasta]
	var $ds = databaseManager.getDataSetByQuery('infocom',$query,args,-1)
	
	if ($ds.getMaxRowIndex() == 0)
	{
		globals.DIALOGS.showWarningDialog('Aviso','No se encontraron resultados','OK')
		return
	}
	forms.rpt_resumen_centro_2.fTotalGral = calcularTotal($ds)
	var $frm = solutionModel.getForm('rpt_resumen_centro_2')
	var $tipos = [JSColumn.INTEGER, JSColumn.NUMBER]
	$frm.dataSource = $ds.createDataSource('RPT_RESUMEN_CENTRO',$tipos)
	forms[$frm.name].controller.recreateUI()
	forms[$frm.name].controller.sort('centro_id asc, razon_social asc')
	forms.rpt_resumen_centro_2.pdf()
}

/**
 * @param {JSDataSet} ds
 *
 * @properties={typeid:24,uuid:"0470DBFB-E4D1-4136-BB5A-6B516ECD311B"}
 */
function calcularTotal(ds)
{
	var $totalGral = 0
	for (var i = 1 ; i <= ds.getMaxRowIndex() ; i++)
	{
		$totalGral += ds.getValue(i,2)
	}
	return $totalGral
}